import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import axios from 'axios'
import VueAxios from 'vue-axios'
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
axios.defaults.baseURL="http://localhost/api"//设置axios请求的根路径
//请求拦截器
// axios.interceptors.request.use(config => {
//     //config.headers.Authorization = window.sessionStorage.getItem('token')
//     config.headers.token = window.sessionStorage.getItem('token')
//     return config
// })
//响应拦截器
// axios.interceptors.response.use(response => {
//     if (response.data.code ==600) {
//         router.push('/login')
//     }
//     return response
// })

// // 请求拦截器
// axios.interceptors.request.use(config => {
//     config.headers.token =sessionStorage.getItem('token');
//     console.log("拦截前获得token")
//     console.log(sessionStorage.getItem('token'))
//     return config;
// })
//
// //响应拦截器
// axios.interceptors.response.use(response => {
//     if(response.data.code === 600) {
//         router.push('/Login')
//     }
//     return response;
// })
createApp(App).use(store).use(VueAxios, axios).use(ElementPlus).use(router).mount('#app')


// 防抖函数
const debounce = (fn, delay) => {
    let timer = null;
    return function () {
        let context = this;
        let args = arguments;
        clearTimeout(timer);
        timer = setTimeout(function () {
            fn.apply(context, args);
        }, delay);
    };
};

// 重写 ResizeObserver
const _ResizeObserver = window.ResizeObserver;
window.ResizeObserver = class ResizeObserver extends _ResizeObserver {
    constructor(callback) {
        callback = debounce(callback, 16); // 设置防抖延迟为 16 毫秒
        super(callback);
    }
};

